package com.hyh.fireworks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.fireworks.common.result.CommonPage;
import com.hyh.fireworks.entity.Photo;
import com.hyh.fireworks.mapper.PhotoMapper;
import com.hyh.fireworks.service.IPhotoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.swing.*;

/**
 * <p>
 * 相册表 服务实现类
 * </p>
 *
 * @author summerday
 * @since 2020-11-07
 */
@Service
public class PhotoServiceImpl extends ServiceImpl<PhotoMapper, Photo> implements IPhotoService {

    @Override
    public CommonPage<Photo> pageList(Long current, Long pageSize) {
        QueryWrapper<Photo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("update_time");
        Page<Photo> photoPage = this.baseMapper.selectPage(new Page<>(current, pageSize), wrapper);
        return CommonPage.restPage(photoPage);
    }

    @Override
    public CommonPage<Photo> pageListByGroup(String groupName, Long current, Long pageSize) {
        QueryWrapper<Photo> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("update_time");
        if(groupName != null){
            wrapper.eq("team",groupName);
        }
        Page<Photo> photoPage = this.baseMapper.selectPage(new Page<>(current, pageSize), wrapper);
        return CommonPage.restPage(photoPage);
    }
}
